<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
  <script src="../js/vue-router.js"></script>
</head>

<body>
  <div id="app">
    <!-- 路由跳转的按钮 -->
    <router-link to="/a">跳转至组件A</router-link>
    <router-link to="/b">跳转至组件B</router-link>
    <!-- 组件加载的视口 -->
    <router-view></router-view>
  </div>
  <script>
    // 1.定义组件
    let comA = {
      template: `
        <div>
          我是A组件
        </div>
      `
    }
    let comB = {
      template: `
        <div>
          我是B组件
        </div>
      `
    }
    // 2.定义路由
    let router = new VueRouter({
      routes: [
        // { path: '/', redirect: '/a' },
        { path: '/', redirect: { name: 'coma' } },
        { path: '/a', component: comA, name: 'coma' },
        { path: '/b', component: comB, alias: '/B' },
      ]
    })

    let vm = new Vue({
      el: "#app",
      data: {

      },
      methods: {

      },
      created() {

      },
      // 3.注册路由
      router
    })
  </script>
</body>

</html>